package com.iaiai.cobra.platform.other.ip;

import com.iaiai.cobra.common.util.JsonUtil;
import com.iaiai.cobra.common.util.web.HttpsUtil;
import com.iaiai.cobra.platform.baidu.bean.BaiduQueryIpv4AddressResponse;
import com.iaiai.cobra.platform.other.ip.bean.PconlineIpAddressResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.hc.core5.http.ParseException;

import java.io.IOException;
import java.net.URISyntaxException;

/**
 * Created with IpAddress.
 * Package: com.iaiai.cobra.platform.other.ip
 * Author: iaiai
 * Create Time: 2024/7/30 21:39
 * QQ: 176291935
 * Email: 176291935@qq.com
 * Description: 根据ipv4查询地址
 */
@Slf4j
public class PconlineIpAddress {

    //查询当前ip地址
    public static PconlineIpAddressResponse queryIpv4Address(String ipv4) throws IOException, URISyntaxException, ParseException {
        String response = new HttpsUtil.Builder().build().get("https://whois.pconline.com.cn/ipJson.jsp?ip="+ipv4+"&json=true");
        log.info("[https://whois.pconline.com.cn] - 反查询ip地址：{}",response);
        return JsonUtil.getInstance().deserialize(response, PconlineIpAddressResponse.class);
    }

}
